/**
 * Copyright 2011 Poltman.Ltd; www.poltman.com. All rights reserved.		
 *
 * This file is part of the dspace-poltman project http://www.poltman.com.
 *
 * This is free software; you can redistribute it and/or modify it under
 * the terms of DuraSpace DSpace license detailed in the LICENSE and NOTICE 
 * files at the root of the source tree and available online at
 * http://www.dspace.org/license/
 * 
 */

package com.poltman.dscentral.db.repository.dspace;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.poltman.dscentral.db.entity.dspace.CommunityEntity;




/**
 * 
 * @author Zbigniew Ciok; z.ciok@poltman.com
 * 
 * @version $Revision: 1809 $
 *
 */
//FIXME: Transactional
public interface CommunityRepository extends JpaRepository<CommunityEntity, Integer> {
	
	@Query("select c from CommunityEntity c where c.communityId not in (select cc.childCommId from Community2CommunityEntity cc) order by c.name")
	List<CommunityEntity> findFirstLevelCommunities();

	public CommunityEntity findByCommunityId(Integer communityId);
	public CommunityEntity findByName(String name);
	
	@SuppressWarnings("unchecked")
	public CommunityEntity save(CommunityEntity community);
	
	@Modifying
	@Query("update CommunityEntity c set c.name = ?1, c.shortDescription = ?2 where c.communityId = ?3")
	public int setFixedNameAndShortDescriptionFor(String name, String shortDescription, Integer communityId);
	
	@Modifying
	@Query("update CommunityEntity c set c.introductoryText = ?1 where c.communityId = ?2")
	public int setFixedIntroductoryTextFor(String introductoryText, Integer communityId);	

	@Modifying
	@Query("update CommunityEntity c set c.copyrightText = ?1 where c.communityId = ?2")
	public int setFixedCopyrightTextFor(String copyrightText, Integer communityId); 
}
